package models

import (
	"time"
)

type IntegrationType string

const (
	IntegrationTypeJira      IntegrationType = "jira"
	IntegrationTypePagerDuty IntegrationType = "pagerduty"
	IntegrationTypeSlack     IntegrationType = "slack"
	IntegrationTypeWebhook   IntegrationType = "webhook"
)

type IntegrationStatus string

const (
	IntegrationStatusActive   IntegrationStatus = "active"
	IntegrationStatusInactive IntegrationStatus = "inactive"
	IntegrationStatusError    IntegrationStatus = "error"
)

type Integration struct {
	ID        string            `bson:"_id,omitempty" json:"id"`
	Type      IntegrationType   `bson:"type" json:"type"`
	Name      string            `bson:"name" json:"name"`
	Status    IntegrationStatus `bson:"status" json:"status"`
	LastSync  time.Time         `bson:"last_sync" json:"last_sync"`
	CreatedAt time.Time         `bson:"created_at" json:"created_at"`
	UpdatedAt time.Time         `bson:"updated_at" json:"updated_at"`
}

// Jira Models
type JiraConfig struct {
	ID               string    `bson:"_id,omitempty" json:"id"`
	BaseURL          string    `bson:"base_url" json:"base_url"`
	Username         string    `bson:"username" json:"username"`
	APIToken         string    `bson:"api_token" json:"api_token"`
	ProjectKey       string    `bson:"project_key" json:"project_key"`
	DefaultIssueType string    `bson:"default_issue_type" json:"default_issue_type"`
	AutoSync         bool      `bson:"auto_sync" json:"auto_sync"`
	CreatedAt        time.Time `bson:"created_at" json:"created_at"`
	UpdatedAt        time.Time `bson:"updated_at" json:"updated_at"`
}

type JiraIssue struct {
	Key         string    `json:"key"`
	ID          string    `json:"id"`
	Summary     string    `json:"summary"`
	Description string    `json:"description"`
	IssueType   string    `json:"issue_type"`
	Priority    string    `json:"priority"`
	Status      string    `json:"status"`
	Assignee    string    `json:"assignee"`
	Reporter    string    `json:"reporter"`
	Created     time.Time `json:"created"`
	Updated     time.Time `json:"updated"`
}

type TicketJiraMapping struct {
	ID        string    `bson:"_id,omitempty" json:"id"`
	TicketID  string    `bson:"ticket_id" json:"ticket_id"`
	JiraKey   string    `bson:"jira_key" json:"jira_key"`
	JiraID    string    `bson:"jira_id" json:"jira_id"`
	CreatedAt time.Time `bson:"created_at" json:"created_at"`
	UpdatedAt time.Time `bson:"updated_at" json:"updated_at"`
}

// PagerDuty Models
type PagerDutyConfig struct {
	ID                  string    `bson:"_id,omitempty" json:"id"`
	APIKey              string    `bson:"api_key" json:"api_key"`
	ServiceID           string    `bson:"service_id" json:"service_id"`
	EscalationPolicyID  string    `bson:"escalation_policy_id" json:"escalation_policy_id"`
	AutoCreateIncident  bool      `bson:"auto_create_incident" json:"auto_create_incident"`
	CreatedAt           time.Time `bson:"created_at" json:"created_at"`
	UpdatedAt           time.Time `bson:"updated_at" json:"updated_at"`
}

type PagerDutyIncident struct {
	ID                 string    `json:"id"`
	IncidentNumber     string    `json:"incident_number"`
	Title              string    `json:"title"`
	Description        string    `json:"description"`
	Status             string    `json:"status"`
	Urgency            string    `json:"urgency"`
	ServiceID          string    `json:"service_id"`
	EscalationPolicyID string    `json:"escalation_policy_id"`
	AssigneeIDs        []string  `json:"assignee_ids"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
}

type AlertPagerDutyMapping struct {
	ID          string    `bson:"_id,omitempty" json:"id"`
	AlertID     string    `bson:"alert_id" json:"alert_id"`
	IncidentID  string    `bson:"incident_id" json:"incident_id"`
	CreatedAt   time.Time `bson:"created_at" json:"created_at"`
	UpdatedAt   time.Time `bson:"updated_at" json:"updated_at"`
}
